﻿using System;
using System.Threading.Tasks;

namespace Listing1_36
{
    public class Program
    {
        static void Main()
        {
            int n = 0;
            object _lock = new object();
            var up = Task.Run(() =>
            {
                for (int i = 0; i < 100000000; i++)
                    lock (_lock)
                        n++;
            });
            for (int i = 0; i < 100000000; i++)
                lock (_lock)
                    n--;
            up.Wait();
            Console.WriteLine(n);
            Console.ReadKey();
        }
    }
}